import fs from 'fs';
import path from 'path';

export class GlobalData<T> {
  public data: T;
  public init: T;

  constructor(init: T) {
    this.init = { ...init };
    this.data = { ...init };
  }

  setData(data) {
    this.data = data;
  }

  resetData() {
    this.data = { ...this.init };
  }

}

export class ErrorLog {
  logPath: string;

  constructor() {
    this.logPath = path.resolve(__dirname, '../../dist/error.log');
    fs.writeFileSync(this.logPath, '');
  }

  addLog(data) {
    fs.appendFileSync(this.logPath, data);
  }
}